package example.neon;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class JPanelImgAndMsgContent extends JPanel {
    private final float[] dash1 = {5.0f};

    private final BasicStroke basicStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);

    BufferedImage image;

    String[] msgArray = new String[]{"", "", ""};

    public JPanelImgAndMsgContent() {
        int padding = 20;
        this.setBorder(BorderFactory.createEmptyBorder(padding, padding, 330, padding));
        this.setBackground(Color.WHITE);
    }

    public void setImage(BufferedImage image) {
        this.image = image;
        this.repaint();
    }

    public void pushMsg(String msg) {
        msgArray[0] = msgArray[1];
        msgArray[1] = msgArray[2];
        msgArray[2] = msg;
        this.repaint();
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.setStroke(basicStroke);
        g.setFont(Commom.FONT_TIP);
        g.setColor(Color.GRAY);
        g.drawString("要识别的钓鱼WASD按键一定要在下面", 20, 32);
        g.drawString("框里才能正常识别", 20, 46);
        g.drawRect(20, 52, 210, 210);
        if (image != null)
            g.drawImage(image, 25, 57, 200, 200, null);
        g.setColor(Color.BLACK);
        g.fillRect(20, 270, 210, 58);
        g.setColor(Color.WHITE);
        g.drawString(msgArray[0], 25, 287);
        g.drawString(msgArray[1], 25, 304);
        g.drawString(msgArray[2], 25, 321);
    }
}
